//
//  ZYCTeaLeaveHeaderCell.m
//  ZDSC
//
//  Created by 张威 on 2021/11/3.
//

#import "ZYCTeaLeaveHeaderCell.h"
@interface ZYCTeaLeaveHeaderCell ()

@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *deleteButton;

@end
@implementation ZYCTeaLeaveHeaderCell
#pragma mark - setters
- (void)setModel:(ZYCTeaLeaveApplyUserModel *)model{
    _model = model;
    if ([model.nodeType integerValue] == 3) {
        _deleteButton.hidden = NO;
    }else{
        _deleteButton.hidden = YES;
    }
    _titleLabel.text = model.realName;
}


#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self.contentView addSubview:self.iconImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.deleteButton];
        
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0.f);
            make.size.mas_equalTo(CGSizeMake(42.0f, 42.0f));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconImageView.mas_bottom).offset(8.f);
            make.left.right.equalTo(self);
        }];
        
        [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right);
            make.top.equalTo(self.contentView.mas_top);
            make.size.mas_equalTo(CGSizeMake(12, 12));
        }];
    }
    return self;
}

#pragma mark - getters
-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerPlace"]];
        _iconImageView.contentMode = UIViewContentModeScaleAspectFit;
        _iconImageView.layer.cornerRadius = 21.0f;
        _iconImageView.layer.masksToBounds = YES;
    }
    return _iconImageView;
}

-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 13.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentCenter];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UIButton *)deleteButton {
    if (!_deleteButton) {
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_deleteButton setImage:[UIImage imageNamed:@"sc"]  forState:UIControlStateNormal];
        [_deleteButton addTarget:self action:@selector(clickDeleteAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteButton;
}

- (void)clickDeleteAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(teaLeaveHeaderCellDeleteApprover:)]) {
        [self.delegate teaLeaveHeaderCellDeleteApprover:self.model];
    }
}
@end
